<html>
<head><meta charset="utf-8"><title>cgu partitioning questions · t-compiler/wg-incr-comp · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/index.html">t-compiler/wg-incr-comp</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html">cgu partitioning questions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204429332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204429332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204429332">(Jul 20 2020 at 14:32)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="312719">@Xavier Denis</span> <span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span></p>



<a name="204429354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204429354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204429354">(Jul 20 2020 at 14:32)</a>:</h4>
<p><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span></p>



<a name="204429399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204429399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204429399">(Jul 20 2020 at 14:32)</a>:</h4>
<p>this is mostly a reiteration of the questions i was raising in <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/const.20prop.20into.20operands">https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/const.20prop.20into.20operands</a> and with <span class="user-mention" data-user-id="125250">@Wesley Wiser</span>  in DMs. But I'm curious how propagating constants into operands would cause partitioning changes that lead to 12% increase in build times</p>



<a name="204429487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204429487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204429487">(Jul 20 2020 at 14:33)</a>:</h4>
<p>Yeah, it's a really interesting question!</p>



<a name="204429489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204429489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204429489">(Jul 20 2020 at 14:33)</a>:</h4>
<p>and more specifically how can we debug this? It'd be interesting to see how the groups are generated</p>



<a name="204429528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204429528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204429528">(Jul 20 2020 at 14:33)</a>:</h4>
<p>I'll try to explain what I've seen happen and why I think it's happening</p>



<a name="204429530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204429530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204429530">(Jul 20 2020 at 14:33)</a>:</h4>
<p>because I fail to see how operand propagation would make a <code>println!</code> affect partitioning</p>



<a name="204429595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204429595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204429595">(Jul 20 2020 at 14:34)</a>:</h4>
<p>the two seem... orthogonal</p>



<a name="204429951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204429951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204429951">(Jul 20 2020 at 14:37)</a>:</h4>
<p>So, to give some back story, there are kind of two main factors to the partitioning system currently: what goes in a CGU and how big is the CGU. Initially what goes in the CGU is based on the Rust module. IIRC, for each module in the crate we generate two CGUs: one for code which is monomorphic to start with and one for monomorphic instantiations of polymorphic functions (ie, generic code). As for how big the CGU is, this is just the sum of the cost estimates for each item in the CGU. I believe currently, this just boils down to a "count of MIR statements in the function".</p>



<a name="204430116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204430116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204430116">(Jul 20 2020 at 14:38)</a>:</h4>
<p>However, the actual number of CGUs we're limited to is fixed. I believe you can control this via a <code>-C</code> flag but the default is like <code>128</code> or something. So when we have more CGUs than we're supposed to, we order all the CGUs by their size and start merging the smallest ones together until we're under the limit.</p>



<a name="204430972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204430972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204430972">(Jul 20 2020 at 14:44)</a>:</h4>
<p>it'd be interesting to see if that change to mir-opt causing a regression was just 'bad luck' ie the CGU in question was just at the limit and adding a println just pushed things over the edge but then these benchmarks seem quite limiting and don't seem to capture interesting properties when we're making changes to code being generated!</p>



<a name="204431536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431536">(Jul 20 2020 at 14:48)</a>:</h4>
<p>That's the part that's causing some of our MIR-opts issues I believe. Let me show an example:</p>
<p>Suppose we have a crate that ends up with CGUs like this:</p>
<ul>
<li>CGU 0: Size 10,000</li>
<li>CGU 1: Size 8,000</li>
<li>CGU 2: Size 5,000</li>
<li>CGU 3: Size 500</li>
<li>CGU 4: Size 400</li>
<li>CGU 5: Size 300</li>
</ul>
<p>Now suppose we have limit of 5 CGUs, we'd get a merged CGU result of:</p>
<ul>
<li>CGU 0: Size 10,000</li>
<li>CGU 1: Size 8,000</li>
<li>CGU 2: Size 5,000</li>
<li>CGU (4 + 5): Size 700</li>
<li>CGU 3: Size 500</li>
</ul>
<p>And we have some function that is eligible for the new MIR-opt we're adding. Currently, this function might be getting included in CGU 3. But now since we've optimized that function (maybe a lot) it has a smaller cost which means its initial CGU partition does as well:</p>
<ul>
<li>CGU 0: Size 10,000</li>
<li>CGU 1: Size 8,000</li>
<li>CGU 2: Size 5,000</li>
<li>CGU 3: Size <del>500</del> 399</li>
<li>CGU 4: Size 400</li>
<li>CGU 5: Size 300</li>
</ul>
<p>Well now, since we order by the size and merge the smallest, CGU 3 and CGU 5 are going to be merged:</p>
<ul>
<li>CGU 0: Size 10,000</li>
<li>CGU 1: Size 8,000</li>
<li>CGU 2: Size 5,000</li>
<li>CGU (3 + 5): Size 699</li>
<li>CGU 4: Size 400</li>
</ul>
<p>So the end result CGU that our function ended up in actually grew from <code>500</code> to <code>699</code> which means it will probably take LLVM longer to compile that. Even though our function decreased in size, the module it was a part of changed and got bigger!</p>



<a name="204431807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431807">(Jul 20 2020 at 14:50)</a>:</h4>
<p>But notice too, the total amount of work went down: 10,000 + 8,000 + 5,000 + 500 + 400 + 300 =&gt; 24,200. But in the new version it's only 24,099.</p>



<a name="204431811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431811">(Jul 20 2020 at 14:50)</a>:</h4>
<p>yea but to be clear: this is already the case with no opts</p>



<a name="204431858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431858">(Jul 20 2020 at 14:51)</a>:</h4>
<p>we could engineer a testcase that looks exactly like the optimized one you gave</p>



<a name="204431870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431870">(Jul 20 2020 at 14:51)</a>:</h4>
<p>Yes, for sure!</p>



<a name="204431874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431874">(Jul 20 2020 at 14:51)</a>:</h4>
<p>so that adding a <code>println!</code> also pushes it over the edge</p>



<a name="204431888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431888">(Jul 20 2020 at 14:51)</a>:</h4>
<p>Yep!</p>



<a name="204431922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431922">(Jul 20 2020 at 14:51)</a>:</h4>
<p>I guess more broadly: how valuable are these tests when looking at changes which change the code being generated</p>



<a name="204431942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431942">(Jul 20 2020 at 14:51)</a>:</h4>
<p>/ should we be benchmarking something else?</p>



<a name="204431947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431947">(Jul 20 2020 at 14:51)</a>:</h4>
<p>But perf.rlo isn't measuring the cost of adding the <code>println!()</code> per say, it's measuring how expensive that change is relative from one compiler to another.</p>



<a name="204431956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204431956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204431956">(Jul 20 2020 at 14:51)</a>:</h4>
<p>maybe.. a sequence of changes?</p>



<a name="204432065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204432065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204432065">(Jul 20 2020 at 14:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125250">Wesley Wiser</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/cgu.20partitioning.20questions/near/204431947">said</a>:</p>
<blockquote>
<p>But perf.rlo isn't measuring the cost of adding the <code>println!()</code> per say, it's measuring how expensive that change is relative from one compiler to another.</p>
</blockquote>
<p>yes agreed, but in this case the compilers aren't generating the same mir!</p>



<a name="204432106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204432106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204432106">(Jul 20 2020 at 14:52)</a>:</h4>
<p>those tests make sense to me if we're generating the same mir code but measuring how fast we can generate the same code</p>



<a name="204432200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204432200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204432200">(Jul 20 2020 at 14:53)</a>:</h4>
<p>Yeah, there's a bit of discussion about that idea here <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/brainstorming.3A.20mission.20statement.2C.20goals.2C.20design.20constraints/near/203851817">https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/brainstorming.3A.20mission.20statement.2C.20goals.2C.20design.20constraints/near/203851817</a> and probably else where as well</p>



<a name="204432493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204432493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204432493">(Jul 20 2020 at 14:55)</a>:</h4>
<p>In some sense, it's true that perf.rlo isn't "pure" or whatever because what it's measuring changes but on the other hand, that's also kind of the point. If we're making changes that are theoretically faster but in practice slower, those are bad changes.</p>



<a name="204432526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204432526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204432526">(Jul 20 2020 at 14:55)</a>:</h4>
<p>What we're seeing right now are just the benchmarks being flawed.</p>



<a name="204432642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204432642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204432642">(Jul 20 2020 at 14:56)</a>:</h4>
<p>Which is why we are willing to land changes that look bad in the benchmarks if there's solid evidence to show they aren't bad in the real world.</p>



<a name="204432942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204432942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204432942">(Jul 20 2020 at 14:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125250">Wesley Wiser</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/cgu.20partitioning.20questions/near/204432493">said</a>:</p>
<blockquote>
<p>If we're making changes that are theoretically faster but in practice slower, those are bad changes.</p>
</blockquote>
<p>Agreed, but with changes like this how do we know if it's just 'bad luck' wrt to getting unlucky partitioning changes or reflective of a real slowdown</p>



<a name="204432986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204432986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204432986">(Jul 20 2020 at 14:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312719">Xavier Denis</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/cgu.20partitioning.20questions/near/204431858">said</a>:</p>
<blockquote>
<p>we could engineer a testcase that looks exactly like the optimized one you gave</p>
</blockquote>
<p>This is another reason why we've landed a number of those changes which show "regressions". If the regressions are only appearing because of where the test suite happens to insert the <code>println!()</code> then we're often ok with landing it.</p>



<a name="204433156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204433156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204433156">(Jul 20 2020 at 15:00)</a>:</h4>
<p>semi-related: would it make sense for incr compilation to not change CGUs?</p>



<a name="204433524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204433524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204433524">(Jul 20 2020 at 15:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312719">Xavier Denis</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/cgu.20partitioning.20questions/near/204432942">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="125250">Wesley Wiser</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/cgu.20partitioning.20questions/near/204432493">said</a>:</p>
<blockquote>
<p>If we're making changes that are theoretically faster but in practice slower, those are bad changes.</p>
</blockquote>
<p>Agreed, but with changes like this how do we know if it's just 'bad luck' wrt to getting unlucky partitioning changes or reflective of a real slowdown</p>
</blockquote>
<p>Great question! Here's some of the things I look for to tell if it's the CGU issue:</p>
<ul>
<li>
<p>Are all or nearly all of the regressions isolated to incremental tests? If we see improvements or least no regressions to the non-incremental builds, this is often an indicator.</p>
</li>
<li>
<p>In the detailed report for the incremental tests, is the time being taken up because of more CGUs getting code gen'd? Look for an increase in the number of executions for queries/functions like <code>LLVM_module_codegen</code>.</p>
</li>
</ul>



<a name="204433812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204433812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204433812">(Jul 20 2020 at 15:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312719">Xavier Denis</span> <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/cgu.20partitioning.20questions/near/204433156">said</a>:</p>
<blockquote>
<p>semi-related: would it make sense for incr compilation to not change CGUs?</p>
</blockquote>
<p>I'm not sure I've thought about it enough to have a good opinion but I'm skeptical in general of making the perf test environment too different from what users would normally run themselves.</p>



<a name="204433924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204433924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204433924">(Jul 20 2020 at 15:05)</a>:</h4>
<p>oh i mean in general not change CGUs during incremental compilation :P</p>



<a name="204434002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434002">(Jul 20 2020 at 15:06)</a>:</h4>
<p>or basically say 'only change them if something has majorly changed'</p>



<a name="204434122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434122">(Jul 20 2020 at 15:06)</a>:</h4>
<p>basically make incremental compilation say 'if CGUs are less than 50% out of balance don't bother changing them'</p>



<a name="204434164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434164">(Jul 20 2020 at 15:07)</a>:</h4>
<p>Oh gotcha</p>



<a name="204434279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434279">(Jul 20 2020 at 15:08)</a>:</h4>
<p>basically under the hypothesis that when doing things incrementally changing cgus is not useful and it's better to deal with a single slightly larger / lighter unit than rebalance</p>



<a name="204434322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434322">(Jul 20 2020 at 15:08)</a>:</h4>
<p>IIRC <span class="user-mention" data-user-id="116083">@pnkfelix</span> had a similar idea around here <a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/brainstorming.3A.20mission.20statement.2C.20goals.2C.20design.20constraints/near/203736391">https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/brainstorming.3A.20mission.20statement.2C.20goals.2C.20design.20constraints/near/203736391</a> (you might have to scroll a bit further back to see all of the relevant info).</p>



<a name="204434368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434368">(Jul 20 2020 at 15:09)</a>:</h4>
<p>(btw i checked the operand opt and the worst test case +12% for an incr rebuild has 5 more calls to <code>LLVM_module_codegen</code>)</p>



<a name="204434389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434389">(Jul 20 2020 at 15:09)</a>:</h4>
<p>Yeah seems likely it's the CGU issue then</p>



<a name="204434447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434447">(Jul 20 2020 at 15:09)</a>:</h4>
<p>I've got run but if you have more thoughts, feel free to leave them here and I'll try to reply when I'm back later</p>



<a name="204434623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434623">(Jul 20 2020 at 15:11)</a>:</h4>
<p>yea no worries! I just want to better understand how we rule out opts from normal compilation</p>



<a name="204434697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204434697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204434697">(Jul 20 2020 at 15:12)</a>:</h4>
<p>and it's sad that we could lose an opt like this which should cause many other opts to unblock</p>



<a name="204464142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204464142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204464142">(Jul 20 2020 at 19:18)</a>:</h4>
<p><span class="user-mention" data-user-id="125250">@Wesley Wiser</span> two questions:</p>
<ul>
<li>Since merging CGUs is what makes the times change in strange ways for incremental comp, would it make sense to not merge CGUs <em>at all</em> during incremental compilation?</li>
<li>Ideally one would want the time needed for recompilation after a small change to be constant. For it to be independent of the rest of the crate, and only depend on the size of the change. Could we generate enough CGUs that we get this level of fine-grained behavior on incremental compilation?</li>
</ul>



<a name="204464211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204464211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204464211">(Jul 20 2020 at 19:19)</a>:</h4>
<p>Oh, btw, in this context I mean "incremental compilation for debug builds". Release builds are another story entirely :P</p>



<a name="204503526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/241847-t-compiler/wg-incr-comp/topic/cgu%20partitioning%20questions/near/204503526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/241847-t-compiler/wg-incr-comp/topic/cgu.20partitioning.20questions.html#204503526">(Jul 21 2020 at 01:12)</a>:</h4>
<blockquote>
<p>Since merging CGUs is what makes the times change in strange ways for incremental comp, would it make sense to not merge CGUs at all during incremental compilation?</p>
</blockquote>
<p>That seems like a good experiment to try! I think <code>pnkfelix</code> even suggested splitting large CGUs which also makes a lot of sense. One other thing we've talked about would be scaling the number of CGUs targeted by the size of the crate. </p>
<blockquote>
<p>Ideally one would want the time needed for recompilation after a small change to be constant. For it to be independent of the rest of the crate, and only depend on the size of the change. Could we generate enough CGUs that we get this level of fine-grained behavior on incremental compilation?</p>
</blockquote>
<p>Hopefully yes! We will probably have to change our visibility and linkage code to accommodate having code spread across many CGUs and not clustered together.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>